/*
 * Copyright (c) 2002-2003 by OpenSymphony
 * All rights reserved.
 */
package org.jackysoft.entity;

import java.util.Map;








import org.dom4j.Element;
import org.jackysoft.bean.define.EntitySchemas;

/**
 * @author <a href="mailto:plightbo@hotmail.com">Pat Lightbody</a>
 */


public class ActionNode extends AbstractNode {
	// ~ Instance fields
	// ////////////////////////////////////////////////////////

	/**
	 * 
	 */
	private static final long serialVersionUID = -8537494292218225618L;

	protected PostFunctionsNode postFunctions;
	protected PreFunctionsNode preFunctions;
	protected Map<String, String> metaAttributes;
	protected RestrictionNode restriction;
	protected ResultsNode resultsNode;

	protected String name;
	protected String view;
	protected boolean start = false;
	protected boolean auto = false;
	protected boolean finish = false;

	// ~ Methods
	// ////////////////////////////////////////////////////////////////

	public ActionNode() {

	}

	public ActionNode(Element adc) {
		super(adc);
	}

	@Override
	public Element asElement() {

		Element root = elementof("action");
		attr(root, "id", id);
		attr(root, "name", name);
		attr(root, "view", view);

		attrtrue(root, "auto", auto);
		attrtrue(root, "finish", finish);
		addmetas(root, this.metaAttributes);
		addchild(root, this.preFunctions);
		addchild(root, this.restriction);
		addchild(root, this.resultsNode);
		addchild(root, this.postFunctions);
		return root;
	}

	
	
	public Map<String, String> getMetaAttributes() {
		return metaAttributes;
	}

	public String getName() {
		return name;
	}

	
	
	public PostFunctionsNode getPostFunctions() {
		return postFunctions;
	}

	
	
	public PreFunctionsNode getPreFunctions() {
		return preFunctions;
	}

	
	
	public RestrictionNode getRestriction() {
		return restriction;
	}

	
	
	public ResultsNode getResultsNode() {
		return resultsNode;
	}

	public String getView() {
		return view;
	}

	@Override
	protected void init(Element root) {
		this.name = stringAttr(root, "name");
		this.view = stringAttr(root, "view");
		this.auto = booleanAttr(root, "auto");
		this.finish = booleanAttr(root, "finish");
		this.preFunctions = childof(root, "pre-functions",
				PreFunctionsNode.class);
		this.postFunctions = childof(root, "post-functions",
				PostFunctionsNode.class);
		this.resultsNode = childof(root, "results", ResultsNode.class);
		this.restriction = childof(root, "restrict-to", RestrictionNode.class);
		this.metaAttributes = metas(root);

	}

	public boolean isAuto() {
		return auto;
	}

	public boolean isFinish() {
		return finish;
	}

	public boolean isStart() {
		return start;
	}

	public void setAuto(boolean auto) {
		this.auto = auto;
	}

	public void setFinish(boolean finish) {
		this.finish = finish;
	}

	public void setMetaAttributes(Map<String, String> metaAttributes) {
		this.metaAttributes = metaAttributes;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setPostFunctions(PostFunctionsNode postFunctions) {
		this.postFunctions = postFunctions;
	}

	public void setPreFunctions(PreFunctionsNode preFunctions) {
		this.preFunctions = preFunctions;
	}

	public void setRestriction(RestrictionNode restriction) {
		this.restriction = restriction;
	}

	public void setResultsNode(ResultsNode resultsNode) {
		this.resultsNode = resultsNode;
	}

	public void setStart(boolean start) {
		this.start = start;
	}

	public void setView(String view) {
		this.view = view;
	}

	@Override
	public String tagName() {
		// TODO Auto-generated method stub
		return "action";
	}

}
